﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="IndexAP.aspx.cs" Inherits="DATN.mds.ActionPlanManagement.IndexAP" MasterPageFile="~/InternalSite.Master"%>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent1" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" 
        EnableHistory="True" EnablePageMethods="True" EnableScriptGlobalization="True">
    </asp:ToolkitScriptManager>
    <script type="text/javascript">
    //Reference of the GridView. 
    var TargetBaseControl = null;
    //Total no of checkboxes in a particular column inside the GridView.
    var CheckBoxes;
    //Total no of checked checkboxes in a particular column inside the GridView.
    var CheckedCheckBoxes;
    //Array of selected item's Ids.
    var SelectedItems;
    //Hidden field that wil contain string of selected item's Ids separated by '|'.
    var SelectedValues;

    window.onload = function () {
        //Get reference of the GridView. 
        try {
            TargetBaseControl = document.getElementById('<%= this.Idex_Ac.ClientID %>');
        }
        catch (err) {
            TargetBaseControl = null;
        }

        //Get total no of checkboxes in a particular column inside the GridView.
        try {
            CheckBoxes = parseInt('<%= this.Idex_Ac.Rows.Count %>');
        }
        catch (err) {
            CheckBoxes = 0;
        }

        //Get total no of checked checkboxes in a particular column inside the GridView.
        CheckedCheckBoxes = 0;

        //Get hidden field that wil contain string of selected item's Ids separated by '|'.
        SelectedValues = document.getElementById('<%= this.hdnFldSelectedValues.ClientID %>');

        //Get an array of selected item's Ids.
        if (SelectedValues.value == '')
            SelectedItems = new Array();
        else
            SelectedItems = SelectedValues.value.split('|');

        //Restore selected CheckBoxes' states.
        if (TargetBaseControl != null)
            RestoreState();
    }

    function HeaderClick(CheckBox) {
        //Get all the control of the type INPUT in the base control.
        var Inputs = TargetBaseControl.getElementsByTagName('input');

        //Checked/Unchecked all the checkBoxes in side the GridView & modify selected items array.
        for (var n = 0; n < Inputs.length; ++n)
            if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf('chkBxSelect', 0) >= 0) {
                Inputs[n].checked = CheckBox.checked;
                if (CheckBox.checked)
                    SelectedItems.push(document.getElementById(Inputs[n].id.replace('chkBxSelect', 'hdnFldId')).value);
                else
                    DeleteItem(document.getElementById(Inputs[n].id.replace('chkBxSelect', 'hdnFldId')).value);
            }

        //Update Selected Values. 
        SelectedValues.value = SelectedItems.join('|');

        //Reset Counter
        CheckedCheckBoxes = CheckBox.checked ? CheckBoxes : 0;
    }

    function ChildClick(CheckBox, HCheckBox, Id) {
        //Modifiy Counter;            
        if (CheckBox.checked && CheckedCheckBoxes < CheckBoxes)
            CheckedCheckBoxes++;
        else if (CheckedCheckBoxes > 0)
            CheckedCheckBoxes--;

        //Change state of the header CheckBox.
        if (CheckedCheckBoxes < CheckBoxes)
            HCheckBox.checked = false;
        else if (CheckedCheckBoxes == CheckBoxes)
            HCheckBox.checked = true;

        //Modify selected items array.
        if (CheckBox.checked)
            SelectedItems.push(Id);
        else
            DeleteItem(Id);

        //Update Selected Values. 
        SelectedValues.value = SelectedItems.join('|');
    }

    function RestoreState() {
        //Get all the control of the type INPUT in the base control.
        var Inputs = TargetBaseControl.getElementsByTagName('input');

        //Header CheckBox
        var HCheckBox = null;

        //Restore previous state of the all checkBoxes in side the GridView.
        for (var n = 0; n < Inputs.length; ++n)
            if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf('chkBxSelect', 0) >= 0)
                if (IsItemExists(document.getElementById(Inputs[n].id.replace('chkBxSelect', 'hdnFldId')).value) > -1) {
                    Inputs[n].checked = true;
                    CheckedCheckBoxes++;
                }
                else
                    Inputs[n].checked = false;
            else if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf('chkBxHeader', 0) >= 0)
                HCheckBox = Inputs[n];

        //Change state of the header CheckBox.
        if (CheckedCheckBoxes < CheckBoxes)
            HCheckBox.checked = false;
        else if (CheckedCheckBoxes == CheckBoxes)
            HCheckBox.checked = true;
    }

    function DeleteItem(Text) {
        var n = IsItemExists(Text);
        if (n > -1)
            SelectedItems.splice(n, 1);
    }

    function IsItemExists(Text) {
        for (var n = 0; n < SelectedItems.length; ++n)
            if (SelectedItems[n] == Text)
                return n;

        return -1;
    }     
    </script>

</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent2" runat="server">
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent3" runat="server">
 <head id="Head1" runat="server" />
    
<div id="contentx" class="clearingfix">
                    <center>
                            <br/>
                        <h3>Qu&#7843;n lý khách hàng</h3>
                        <hr/>
                    </center>

              <div class="floatboxinternal">
              <center>

    C&#417; H&#7897;i: 
    
    <asp:DropDownList ID="Idex_OppDdl" runat="server" AutoPostBack="True" 
        onselectedindexchanged="DropDownList1_SelectedIndexChanged">
    </asp:DropDownList>

    <asp:Label ID="Label1" runat="server" Text="Tìm Ki&#7871;m Ho&#7841;t &#272;&#7897;ng T&#7915; Ngày:"></asp:Label>

    <asp:TextBox ID="idex_txtDateFrom" runat="server"></asp:TextBox>
    
        <asp:CalendarExtender ID="TextBox2_CalendarExtender" runat="server" 
        Enabled="True" TargetControlID="idex_txtDateFrom" Format="dd/MM/yyyy"
        DaysModeTitleFormat="dddd dd/MM/yyyy" TodaysDateFormat="dddd dd/MM/yyyy">
        </asp:CalendarExtender>
    
    <asp:Label ID="Label2" runat="server" Text="&#272;&#7871;n Ngày:"></asp:Label>
    
    <asp:TextBox ID="idex_txtDateTo" runat="server"></asp:TextBox>
    
        <asp:CalendarExtender ID="CalendarExtender1" runat="server" 
        Enabled="True" TargetControlID="idex_txtDateTo" Format="dd/MM/yyyy"
        DaysModeTitleFormat="dddd dd/MM/yyyy" >
        </asp:CalendarExtender>

        <asp:Button ID="btt_timkiem_Ac" runat="server" onclick="btt_timkiem_Ac_Click" 
            Text="Tìm Ki&#7871;m" Width="70px" />

&nbsp;<asp:CompareValidator ID="CompareValidator1" runat="server" 
            RowStyle-CssClass = "Grd_Row"
            ControlToCompare="idex_txtDateFrom" ControlToValidate="idex_txtDateTo" 
            ErrorMessage="Xin nh&#7853;p l&#7841;i giá tr&#7883; th&#7901;i gian!" Operator="GreaterThan" 
            SetFocusOnError="True" Type="Date"></asp:CompareValidator>

        <asp:GridView ID="Idex_Ac" runat="server" DataKeyNames="Ac_Id" AutoGenerateColumns="False"
        onrowcommand="GridView1_RowCommand" onrowdeleting="GridView1_RowDeleting" 
        Width="877px" onrowdatabound="GridView1_RowDataBound" EmptyDataText="Không có d&#7919; li&#7879;u nào phù h&#7907;p"
         EmptyDataRowStyle-Font-Bold="true" EmptyDataRowStyle-Font-Size="X-Large" 
            AllowPaging="True" onpageindexchanging="Idex_Ac_PageIndexChanging">
        <Columns>
           
         <asp:TemplateField HeaderText="">
                     <ItemTemplate>
                        <asp:CheckBox ID="chkBxSelect" runat="server" />
                        <asp:HiddenField ID="hdnFldId" runat="server" Value='<%# Eval("Ac_Id") %>' />
                     </ItemTemplate>
                     <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
                     <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
                     <HeaderTemplate>
                        <center><asp:CheckBox ID="chkBxHeader" onclick="javascript:HeaderClick(this);" runat="server" />
                        </center>
                     </HeaderTemplate>
                  </asp:TemplateField>

            <asp:BoundField DataField="Name" HeaderText="Tên" >
            </asp:BoundField>
            <asp:BoundField DataField="Time" HeaderText="Th&#7901;i Gian"
                            DataFormatString="{0:dd'/'MM'/'yyyy}"></asp:BoundField>
            <asp:BoundField DataField="Location" HeaderText="&#272;&#7883;a &#272;i&#7875;m"></asp:BoundField>
            <asp:BoundField DataField="ActualExpense" HeaderText="Chi Phí" DataFormatString="{0:0,0 vn&#273;}"></asp:BoundField>
            <asp:BoundField DataField="ActualRevenue" HeaderText="L&#7907;i Nhu&#7853;n"
                            DataFormatString="{0:0,0 vn&#273;}"></asp:BoundField>
            <asp:TemplateField>
                <HeaderTemplate>Thao Tác</HeaderTemplate>
                <ItemTemplate>
                   <asp:LinkButton ID="LinkButton1" 
                                   CommandArgument='<%# Eval("Ac_Id") %>' 
                                   CommandName="Edit" runat="server">
                                    S&#7917;a</asp:LinkButton>
                    |
                   <asp:LinkButton ID="LinkButton2" 
                                   CommandArgument='<%# Eval("Ac_Id") %>' 
                                   CommandName="Delete" runat="server">
                                    Xóa</asp:LinkButton>
                   
                </ItemTemplate>
                <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" />
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" />
            </asp:TemplateField>
            

        </Columns>
                 
         <FooterStyle BackColor="#004a96" />
                <FooterStyle BackColor="#004a96" />
                <HeaderStyle BackColor="#004a96" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#004a96" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#b4cbd5" ForeColor="Black" Font-Size= "Small" />
                <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />

                <SortedAscendingCellStyle BackColor="#FBFBF2" />
                <SortedAscendingHeaderStyle BackColor="#848384" />
                <SortedDescendingCellStyle BackColor="#EAEAD3" />
                <SortedDescendingHeaderStyle BackColor="#575357" />

                <EmptyDataRowStyle Font-Bold="True" Font-Size="X-Large"></EmptyDataRowStyle>

                <RowStyle Font-Size= "Small" />
                 </asp:GridView>

    <asp:HiddenField ID="hdnFldSelectedValues" runat="server" />

    <asp:Button ID="bt_Creat" runat="server" onclick="bt_Creat_Click" CssClass="bty"
        Text="Tạo Mới!" />

    <asp:Button ID="btnCheckBox" runat="server" Text="Xóa Các M&#7909;c &#272;ã Ch&#7885;n" CssClass="bty"
                       onclick="btnCheckBox_Click" />
    
                   <asp:Label ID="lb_IdCheckBox" runat="server" Text=""></asp:Label>

                   </center>

                   <br/>
                   <br/>
                   </div>
                   </div>
</asp:Content>
